<template>
	<view class="warp">
		<image class="logo" src="/static/images/logo.jpg" mode=""></image>
		<view class="form_box">
			<view class="form_input">
				<image class="icon" src="/static/images/zhuce_icon1.png" mode=""></image>
				<input class="input" type="text" v-model="phone" value="" placeholder="请输入手机号"/>
			</view>
			<view class="form_input">
				<image class="icon" src="/static/images/zhuce_icon2.png" mode=""></image>
				<input class="input" type="password" v-model="pwd"  value="" placeholder="请输入密码"/>
			</view>
			<view class="zhuce"  style="display: flex;justify-content: space-between;">
				<!-- <view @click="scan">
					扫码注册
				</view> -->
				<view @click="zhuce">
					忘记密码
				</view>
			</view>
			<view class="xieyi">
				<checkbox value="" @click="checkboxChange" style="transform:scale(0.7)"/>
				<view class="p">请同意<text @click="jump">《隐私政策和用户协议》</text></view>
			</view>
			<view class="form_btn" @click="login" >登录</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phone:'',
				pwd:'',
				check:false
			};
		},
		onLoad() {
			
		},
		methods:{
			checkboxChange() {
				this.check=!this.check;
			},
			scan(){
				// 允许从相机和相册扫码
				uni.scanCode({
				    success: function (res) {
				        console.log('条码类型：' + res.scanType);
				        console.log('条码内容：' + res.result);
						var data=res.result.split('|');
						if(data[0]==1){
							uni.redirectTo({
								url:'/pages/zhuce/zhuce?pid='+data[1]
							})
						}else{
							uni.showToast({
								title:"请先注册",
								icon:'none'
							})
							return  false;
						}
				    }
				});
			},
			yanzhe_p(){
				var phoneReg = /^1[123456789]\d{9}$/;
				var phone =  this.phone.trim();
				if (!phoneReg.test(phone)) {
					return false;
				}else{
					return true;
				}
			},
			//提交登录
			login(){
				if(!this.yanzhe_p()){
					uni.showToast({
						title:"请输入正确的手机号",
						icon:'none'
					})
					return  false;
				}
				var pwd = this.pwd
				if(pwd.length ==0){
					uni.showToast({
						title:"密码不能为空",
						icon:'none'
					})
					return false;
				}
				if(!this.check){
					uni.showToast({
						title:"请同意用户协议和隐私政策",
						icon:'none'
					})
					return;
				}
				var uuid=uni.getStorageSync('uuid');
				this.$http.get('login/login',{'phone':this.phone,'pwd':this.pwd,'uuid':uuid}).
				then(function (response) {
					if(response.code==1){
						//登录成功
						uni.setStorageSync('user',response.data);
						uni.setStorageSync('token',response.data['appToken']);
						console.log(uni.getStorageSync('user'));
						uni.showToast({
							title:"登录成功",
							icon:'none'
						})
						setTimeout(function() {
							 uni.reLaunch({
								url: '/pages/index/index'
							})
						}, 1500);
					}else if(response.code==2){
						uni.showToast({
							title:"您已被禁用，请联系系统管理员",
							icon:'none'
						})
					}else{
						uni.showToast({
							title:"手机号或密码错误",
							icon:'none'
						})
					}
				}).catch(function (error) {
					console.log(error);
				});
				
				
			},
			zhuce(index){
				uni.navigateTo({
					url:'/pages/wangjimima/wangjimima'
				})
			},
			jump(index){
				uni.navigateTo({
					url:'/pages/yinsixieyi/yinsixieyi'
				})
			}
		}
	}
</script>

<style lang="scss">
	.zhuce{
		width:100%;
		text-align: right;
		height:60rpx;
		line-height: 60rpx;
		color:#564c4c;
		font-size: 26rpx;
	}
	.firsttip{
		padding:100rpx 50rpx 0 50rpx;
		width:95%;
		height:100%;
		position: fixed;
		top:88rpx;
		background-color: #ffffff;
	}
	.xieyi{
		display: flex;
		height: 46rpx;
		margin-bottom: 20rpx;
		margin-top: 110rpx;
		.p{
			font-size: 24rpx;
			color: #a5a5a5;
			line-height: 46rpx;
		}
	}
	.warp{
		padding-top: 160rpx;
		.logo{
			display: block;
			width: 470rpx;
			height:255rpx;
			margin: 0 auto;
			margin-top: 100rpx;
		}
		.form_box{
			padding: 142rpx 80rpx 0;
			.form_input{
				height: 100rpx;
				border-bottom: 1px solid #e5e5e5;
				display: flex;
				.icon{
					display: block;
					width: 28rpx;
					height: 32rpx;
					margin-top: 44rpx;
					margin-right: 30rpx;
				}
				.input{
					display: block;
					height: 80rpx;
					line-height: 80rpx;
					margin-top: 20rpx;
					font-size: 30rpx;
					flex: 1;
				}
				.btn{
					height: 50rpx;
					line-height: 50rpx;
					background: #284179;
					border-radius: 5rpx;
					font-size: 24rpx;
					padding: 0 10rpx;
					margin-top: 25rpx;
					color: #fff;
				}
			}
			.form_text{
				height: 45rpx;
				line-height: 45rpx;
				display: flex;
				justify-content: space-between;
				margin-top: 20rpx;
				.text{
					font-size: 26rpx;
					color: #564c4c;
				}
			}
			.form_btn{
				width: 100%;
				height: 90rpx;
				border-radius: 45rpx;
				line-height: 90rpx;
				text-align: center;
				font-size: 32rpx;
				background: #284179;
				color: #fff;
				margin-top:80rpx;
			}
			.xieyi{
				display: flex;
				height: 46rpx;
				margin-bottom: 20rpx;
				margin-top: 34rpx;
				.p{
					font-size: 24rpx;
					color: #284179;
					line-height: 46rpx;
				}
			}
		}
	}
</style>
